<?php $this->start('admin_menu')?>
	<?php echo $this->element('admin_menu', array('str_item' => 'theathers')) ?>
<?php $this->end(); ?>

<div class="theathers view">
	<h1><?php echo __('Theather'); ?> - <?php echo h($theather['Theather']['name']); ?></h1>
	<?php echo $this->Session->flash(); ?>
	<h3><?php echo __('Seats chart'); ?></h3>
	<?php if (!empty($theather['Seat'])): ?>
		<div id='seatchart'>
			<div class='screen'>
				<?php echo $this->Html->image('screen.png'); ?>
			</div>
			<div class='seatmap'>
				<table cellpadding="0" cellspacing="0" class="table-listing" style='margin:auto;'>
				<?php
				$index = 0;
				$rows = count($seats);
				for($i = 1; $i <= 13; $i++){ ?>
					<tr>
					<?php 
					for($j = 1; $j <= 12; $j++){ $index++;?>
						<td style="text-align:center;">
							<?php if(isset($seats[$i][$j])): ?>
							<?php
								if($seats[$i][$j]['status']==1 && $seats[$i][$j]['seat_type_id'] == 1){
									echo $this->Html->tag('div', $index, array('class' => 'chair1 chair', 'id' =>  "seat".$seats[$i][$j]['id'], 'onClick' => "updateSeat(".$index.",".$seats[$i][$j]['id'].");"));
								}elseif($seats[$i][$j]['status']==1 && $seats[$i][$j]['seat_type_id'] == 2){
									echo $this->Html->tag('div', $index, array('class' => 'chair2 chair', 'id' =>  "seat".$seats[$i][$j]['id'], 'onClick' => "updateSeat(".$index.",".$seats[$i][$j]['id'].");"));
								}elseif($seats[$i][$j]['status']==0){
									echo $this->Html->tag('div', "", array('class' => 'chair0 chair', 'id' =>  "seat".$seats[$i][$j]['id'], 'onClick' => "updateSeat('',".$seats[$i][$j]['id'].");"));
								}else{
									echo $this->Html->tag('div', "", array('class' => 'chair3 chair', 'id' =>  "seat".$seats[$i][$j]['id']));
								}
							?>
							<?php endif; ?>
						</td>
					<?php } ?>
					</tr>
				<?php } ?>
				</table>
			</div>
		</div>
	<?php else: ?>
		<?php echo $this->Html->link('Create seats chart', "#", array('class' => 'create-seat-map')) ?>
	<?php endif; ?>
	<!-- modal content -->
	<div id="basic-modal-content">
		<h3>Create Seats Chart</h3>
		<?php echo $this->Form->create(null, array('action' => 'createSeats'));?>
		<input type='hidden' name='id' value='<?php echo $theather['Theather']['id'] ?>' />		
		<table >
			<tr>
				<td>How many rows?</td>
				<td><input type='text' name='rows' /></td>
			</tr>
			<tr>
				<td>How many columns?</td>
				<td><input type='text' name='columns' /></td>
			</tr>
			<tr>
				<td></td>
				<td></td>
			</tr>
		</table>
		<?php echo $this->Form->end(__('Submit', true)); ?>
	</div>
	
	<div id="seatupdate">
		<h3>Update Seat</h3>
		<div id='content-seat-edit'></div>
	</div>
</div>

<div class='actionct'>
	<span class='btn-act'>
		<span><?php echo $this->Html->link(__('List Theathers'), array('action' => 'index'), array('class' => 'back-act')); ?></span>
	</span>
	<span class='btn-act'>
		<span>				
			<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $theather['Theather']['id']), array('class' => 'del-link'), __('Are you sure you want to delete # %s?', $theather['Theather']['id'])); ?>				 
		</span>
	</span>
	<span class='btn-act'>
		<span>
			<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $theather['Theather']['id']), array('class' => 'edit-link')); ?> 
		</span>
	</span>
	<span class='btn-act'>
		<span><?php echo $this->Html->link(__('New'), array('action' => 'add')); ?></span>
	</span>
</div>


<?php $this->start('css') ?>
	<?php echo $this->Html->css('basic'); ?>
<?php $this->end()?>

<?php $this->start('script') ?>
	<?php echo $this->Html->script('jquery.simplemodal'); ?>
	<?php echo $this->Html->script('jquery.form'); ?>
	<script type="text/javascript">
		jQuery(document).ready(function(){
			$('.create-seat-map').click(function (e) {
				$('#basic-modal-content').modal();
				return false;
			});
			$('#updateSeat').ajaxForm();
		});
		
		function updateSeat(index, seatId){
			jQuery.ajax({
			  type: "get",
			  url: "<?php echo $this->Html->url(array('controller' => 'seats', 'action' => 'updateStatus')) ?>/" + seatId
			}).done(function(html) {
				$('#content-seat-edit').append(html);			  
			});
			
			$('#seatupdate').modal();
		}
	</script>
<?php $this->end()?>



	<div class="actions">
		<ul>
			<li><?php echo $this->Html->link(__('New Seat'), array('controller' => 'seats', 'action' => 'add')); ?> </li>
		</ul>
	</div>
</div>



